package ipt.dao.f3;

import ipt.enumeracion.Rol;
import ipt.exp.AlumnoException;
import ipt.vo.Alumno;

import java.util.Iterator;
import java.util.List;

public class ProbarAlumnoDao {

	static AlumnoJDBCDAO dao = new AlumnoJDBCDAO();
	static AlumnoTXTDAO daoTXT = new AlumnoTXTDAO();
	 
    public static void main(String[] args) {

//    	probar_JDBC();
//    	probar_TXT();
    	dao.insertTransaction(daoTXT.getAlumnos());
	   	
    }
    
    public static void probar_JDBC(){
    	mostrarAlumnos(dao.getAlumnos());
	   	
	   	try {
		   	System.out.println();
		   	System.out.println("GET BY DNI 00000001A");
		   	Alumno a=dao.getAlumnoByDni("00000001A");
		   	System.out.println(a);
	   	} catch (AlumnoException e) {
	   		e.printStackTrace();
	   	}
	   	
	   	try {
		   	System.out.println();
		   	Alumno a=new Alumno ("Montgomery","Burns","Tardo","00000001A","montgomery@burns.com",96,Rol.JEFE);
		   	boolean updated=dao.udapteAlumno(a);
		 	System.out.println("updated : "+updated);
	   	} catch (AlumnoException e) {
	   		e.printStackTrace();
	   	}
	   	
	   	mostrarAlumnos(dao.getAlumnos());
	   	
	   	try {
		   	System.out.println();
		   	boolean inserted=dao.deleteAlumno("00000001A");
		 	System.out.println("deleted : "+inserted);
	   	} catch (AlumnoException e) {
	   		e.printStackTrace();
	   	}
	   	
	   	mostrarAlumnos(dao.getAlumnos());
	   	
	   	try {
		   	System.out.println();
		   	Alumno a=new Alumno ("Montgomery","Burns","Tardo","00000001A","montgomery@burns.com",99,Rol.JEFE);
		   	boolean inserted=dao.insertAlumno(a);
		 	System.out.println("inserted : "+inserted);
	   	} catch (AlumnoException e) {
//	   		e.printStackTrace();
	   	}
	   	
	   	mostrarAlumnos(dao.getAlumnos());
    }
    
    public static void probar_TXT(){
    	
    	mostrarAlumnos(daoTXT.getAlumnos());
	   	
//	   	try {
//		   	System.out.println();
//		   	System.out.println("GET BY DNI 00000001A");
//		   	Alumno a=dao.getAlumnoByDni("00000001A");
//		   	System.out.println(a);
//	   	} catch (AlumnoException e) {
//	   		e.printStackTrace();
//	   	}
	   	
//	   	mostrarAlumnos(daoTXT.getAlumnos());
    }
    
    public static void mostrarAlumnos(List<Alumno> lista){
    	System.out.println();
	   	Iterator<Alumno> it2 = lista.iterator();
	   	while ( it2.hasNext() ){
	   		Alumno a = it2.next();
	   		System.out.println(a);
	   		a=null;
	   	}
    }
	
}
